﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoursquareNET.Tip
{
    public class GetNearby
    {
        private const string URL = "http://api.foursquare.com/v1/tips";
        private const Common.HttpRequestMethod HTTP_REQUEST_METHOD = Common.HttpRequestMethod.GET;
        
        private List<Parameter> Parameters = new List<Parameter>();

        /// <summary>
        /// Returns a list of tips near the area specified. (The distance returned is in meters).
        /// </summary>
        /// <param name="returnFormat"></param>
        public GetNearby()
        {
            
        }

        public List<Schema.TipGroup> Execute(Credential credential)
        {
            Parameters.Clear();
            Parameters.Add(_Geolat);
            Parameters.Add(_Geolong);
            Parameters.Add(_Limit);

            string result = Common.HTTPPost(URL, Parameters, credential, HTTP_REQUEST_METHOD);

            return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Schema.TipsObj>(result).Groups;
        }

        #region Parameters

        private Parameter _Geolat = new Parameter("Geolat", "geolat", true);
        private Parameter _Geolong = new Parameter("Geolong", "geolong", true);
        private Parameter _Limit = new Parameter("Limit", "l", false);

        /// <summary>
        /// latitude (required)
        /// </summary>
        public string Geolat { set { _Geolat.Value = value; } }

        /// <summary>
        /// longitude (required)
        /// </summary>
        public string Geolong { set { _Geolong.Value = value; } }

        /// <summary>
        /// limit of results (optional, default 30)
        /// </summary>
        public int? Limit { set { _Limit.Value = value != null ? value.ToString() : string.Empty; } }

        #endregion
    }
}
